package com.cldz.controller;

import com.cldz.common.dto.req.DevChannelDto;
import com.cldz.common.dto.res.DeviceChannelResDto;
import com.cldz.feign.DevChannelFeign;
import com.cldz.response.support.ServerResponse;
import com.cldz.service.DevChannelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ Author     ：lixiao.
 * @ Date       ：Created in 13:19 2018/12/18
 * @ Description：
 * @ Modified By：
 */
@Slf4j
@RestController
public class DevChannelController implements DevChannelFeign {

    @Autowired
    private DevChannelService devChannelService;

    /**
     * 获取遥调通道
     * @param devID
     * @return
     */
    @GetMapping("/regulatChannel/{devID}")
    public ServerResponse getRegulatChannel(@PathVariable(name = "devID")Integer devID){
        List<DeviceChannelResDto> regulatChannel = devChannelService.getRegulatChannel(devID);
        return ServerResponse.createDataList(regulatChannel);
    }

    /**
     * 获取遥控通道
     * @param devID
     * @return
     */
    @GetMapping("/controlChannel/{devID}")
    public ServerResponse getControlChannel(@PathVariable(name = "devID")Integer devID){
        List<DeviceChannelResDto> list = devChannelService.getControlChannel(devID);
        return ServerResponse.createDataList(list);
    }

    /**
     * 根据设备ID获取通道值属性列表
     * @param devChannelDto
     * @return
     */
    @GetMapping("/valueMeanListWithDevID")
    public ServerResponse getValueMeanListWithDevID(DevChannelDto devChannelDto){
        return ServerResponse.createDataList(devChannelService.getValueMeanListWithDevID(devChannelDto));
    }

    /**
     * 根据设备类型获取通道值属性列表
     * @param devChannelDto
     * @return
     */
    @GetMapping("/valueMeanListWithDevType")
    public ServerResponse getValueMeanListWithDevType(DevChannelDto devChannelDto){
        return ServerResponse.createDataList(devChannelService.getValueMeanListWithDevType(devChannelDto));
    }

    /**
     * 获取设备通道
     * @param devChannelDto
     * @return
     */
    @GetMapping("/devChannels")
    public ServerResponse getDevChannels(DevChannelDto devChannelDto){
        List<DeviceChannelResDto> list = devChannelService.getDevChannels(devChannelDto);
        Integer amount = devChannelService.getDevChannelsAmount(devChannelDto);
        return ServerResponse.createDataAndCount(amount,list);
    }

    /**
     * 根据通道类型获取设备通道
     * @param devChannelDto
     * @return
     */
    @GetMapping("/devChannelsWithType")
    public ServerResponse getDevChannelsWithTypeID(DevChannelDto devChannelDto){
        List<DeviceChannelResDto> list = devChannelService.getDevChannelsWithTypeID(devChannelDto);
        Integer amount = devChannelService.getDevChannelsAmountWithTypeID(devChannelDto);
        return ServerResponse.createDataAndCount(amount,list);
    }

    /**
     * 获取指定通道信息
     * @param devChannelDto
     * @return
     */
    @GetMapping("/getSpecifyChannel")
    public ServerResponse getSpecifyChannel(DevChannelDto devChannelDto){
        DevChannelDto data = devChannelService.getSpecifyChannel(devChannelDto);
        return ServerResponse.createDataList(data);
    }

    /**
     * 获取基础通道信息
     * @return
     */
    @GetMapping("/baseChannels")
    public ServerResponse getBaseChannels(DevChannelDto devChannelDto){
        List<DeviceChannelResDto> baseChannels = devChannelService.getBaseChannels(devChannelDto);
        Integer baseChannelsAmount = devChannelService.getBaseChannelsAmount(devChannelDto);
        return ServerResponse.createDataAndCount(baseChannelsAmount,baseChannels);
    }


}
